# -*- coding: utf-8 -*-
#from Carbon.Icons import ttDisabled
print "helloworld";
print 45678+0x12fd2
print "Learn Python in imooc"
print 100 < 99
print 0xff == 255
print 'Python was started in 1989 by "Guido".'
print 'Python was\'t started in 1989 by "Guido"'
print r'''Python is't started in 1989 by "Guido"'''
print r'''"To be, or not to be": 
that is the question.Whether it's nobler in the mind to suffer.'''

s = ur'''Python的Unicode字符串支持"中文",
"日文",
"韩文"等多种语言'''
print s.index("") #打印s

a = True
print a 
print a and 'a=T' or 'a=F'
print 'a=T' or 'a=F'
print 'a=T'
print 'a=F'

classmates = ['Michael', 'Bob', 'Tracy']
print classmates
l = ['Adam','95.5','Lisa','85','Bart','59']
print l[0]
print l[-6]
test=l.pop()
print test


t=('a','b',classmates);
print t;
classmates[1]='benben';
print t;
#循环语句
age = 20
if age >= 18:
    print 'your age is', age
    print 'adult'
print 'END'

if age >= 18:
    print 'adult'
else:
    print 'teenager'

if age >= 18:
    print 'adult'
elif age >= 6:
    print 'teenager'
elif age >= 3:
    print 'kid'
else:
    print 'baby'
    
    
#age = 8
if age >= 6 and age <18:
    print 'teenager'
elif age >= 18:
    print 'adult'
else:
    print 'kid'
num=0
print "for循环"
print l
for name in l:
    print num
    if num % 2 == 0:
        print 'name is :'+name
    else:
        print '成绩:'+name
    num=num+1

N = 10
x = 0
while x < N:
    print x
    x = x + 1
#多重循环    
for x in ['A', 'B', 'C']:
    for y in ['1', '2', '3']:
        print x + y
        
#dict
print'dict集合'
d={
   'Adam': 95,
   'juice': 98,
   'lemon': 100
}
print len(d)
print d.get('Adam')
print d.iterkeys()
print d.has_key('juice')
if 'Paul' in d:
    print d['Paul']

print d
for key in d:
    print key
    
s=set(['A','B','C'])
print s
print len(s)
s = set([('Adam', 95), ('Lisa', 85), ('Bart', 59)])
for list in s:
    print "name is :" + list[0]
    print "scores is :" + str(list[1])

for x,y in s:
    print x,':',y
    
#set 改变值
print '改变set的值'
s = set(['Adam', 'Paul'])
L = ['Adam', 'Lisa', 'Bart', 'Paul']
for i in L:
    if i not in s:
        s.add(i)
print s;
#range
L = [x*x for x in range(1,3)]
print L
print sum(L)

def aaa(a):
    if a==1:
        return 'baob'
    else:
        print '0'
print aaa(1);

#python 返回多个值,实质是返回一个tuple
import math
def move(x, y, step, angle):
    nx = x + step * math.cos(angle)
    ny = y - step * math.sin(angle)
    return nx, ny
x, y = move(100, 100, 60, math.pi / 6)
print x,y

r = move(100, 100, 60, math.pi / 6)
print r
print r[0] ,r[1]
#python 函数递归调用
def fact(n):
    if n == 1:
        return 1
    return n * fact( n - 1 )

print fact(6)
#默认参数转换
print int('123',8)

#计算x的n次方
def power(x,n):
    s=1
    while n > 0:
        n = n - 1 
        s = s * x
    return s
        
print power (3,2)
#假设计算平方的次数最多，我们就可以把 n 的默认值设定为 2：
def power1(x,n=2):
    s=1
    while n > 0:
        n = n - 1 
        s = s * x
    return s
print power1 (3)
#定义可变参数
def fn(*args):
    print len(args)
    s = 0
    for i in args:
        s = s + i
        print s
    return s
print fn(1,2,3)
print l
print l[0:3]
print l[-4:-1]
print l[::3]
str = ur'''Python的Unicode字符串支持"中文",
"日文",
"韩文"等多种语言'''
print str[1:17]

for t in enumerate(l):
    index = t[0]
    name = t[1]
    print index, '-', name
print 'wo shi tt'
print l
for tt in l:
    print tt
print 'zip()函数可以将两个list变成一个'
l1=['a','b','c'] 
l2=[1,2,3]
print zip(l1,l2)
for t3 in zip(range(1,5),l):
    index = t3[0]
    name = t3[1]
    print index, '-', name
#dixt的迭代value
print 'dixt的迭代'
dictsum =0
numdict=0
for dv in d.itervalues():
    dictsum = dictsum+dv
    numdict=numdict+1
avage = dictsum / numdict
print '平均值：',avage
#dixt的迭代key和value
print 'dict的迭代key和value'
for key, value in d.items():
    print key, ':' ,value

for x in range(1,20):
    L.append(x * x)
print d
print d.iteritems()
tds = ['<tr><td>%s</td><td>%s</td></tr>' % (name, score) for name, score in d.iteritems()]
print tds
print '<table>'
print '<tr><th>Name</th><th>Score</th><tr>'
print '\n'.join(tds)
print '</table>'
#条件判断
print '条件判断'
print [x*x for x in range(1,20) if x%2 == 0]
print [m + n for m in 'ABC' for n in '123']
    

def average2(*args):
    if len(args) == 0:
        return 0
    else:
        return sum(args)/len(args)
print average2()
print average2(1, 2)
print average2(1, 2, 2, 3, 4)









    